<template>
	<view >
		<view class="top" >
			<view class="order-nav" :style="{top:BarTop + 'px',height:BarHeight + 'px',lineHeight:BarHeight + 'px'}">
				<view class="nav-content">
					<image src="https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/img/back.png" mode="" class="order-nav-img" @click="backNav"></image>
					<view class="navtitle">
						今日推荐
					</view>
				</view>
			</view>
			<view class="box" :style="{top:BarTop + BarHeight + 8 + 'px'}" @click="GotoSearch">
				<u-search disabled placeholder="搜索想要兑换的商品" bg-color='#F9FFFD' :clearabled='false' v-model="keyword" :show-action='false'  class="search"></u-search>
				<view class="box1" @click="GotoSearch">
					<view class="search-sp">
						搜索
					</view>
				</view>
			</view>
		</view>
		<view style="width: 750rpx;height: 260rpx;"></view>
		<view class="main">
			<view class="mainbox" v-for="(item,index) in data" :key="index" @click="GotoInfo(item)">
				<image :src="item.image" mode="" class="mainimg"></image>
				<view class="main-title">
					{{item.title}}
				</view>
				<view class="main-price">
					<text style="font-size: 28rpx;">券</text>{{item.price}}
				</view>
				<view class="main-btn">
					立即兑换
				</view>
			</view>
			<u-loadmore :status="status" style="width: 100%;text-align: center;"/>
		</view>
		<uv-back-top :scroll-top="scrollTop" style="height: 2000px;" ref="backTop" top="600" z-index="999"></uv-back-top>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				BarTop:'',
				BarHeight:'',
				cateList: [],
				scrollTop: 0,
				status: 'loadmore',
				page:1,
				pagesize:10,
				obj:{
					pagesize:10,
					page:1
				},
				data:'',
				title:''
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
			// #ifdef APP-NVUE
			this.scrollTop = e.detail.scrollTop;
			// #endif
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = ++ this.page;
			let page = {
				page:this.page,
				pagesize:this.pagesize
			}
			
			this.$u.api.shop.getGoods(this.obj,page,{pages:'index'}).then(res =>{
				if(res.code == 1){
					this.data = [...this.data,...res.data.data]
					if(res.data.data.length == 0){
						this.status = 'nomore'
					}
				}
			})
			
		},
		methods:{
			GotoSearch(){
				uni.navigateTo({
					url:'./search'
				})
			},
			GotoInfo(item){
				uni.navigateTo({
					url:`./product?id=${item.id}`
				})
			},
			backNav(){
				uni.navigateBack({
				    delta: 1,
				})
			},
		},
		onShow() {
			
		},
		onLoad(option) { 
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			   this.BarTop = menuButtonInfo.top;
			   this.BarHeight = menuButtonInfo.height;
	
			this.$u.api.shop.getYoulike(this.obj,{pages:'index'}).then(res =>{
				if(res.code == 1){
					this.data = res.data.data
					if(res.data.data.length == 0){
						this.status = 'nomore'
					}
				}
			})
			
		}
	}
</script>
<style>
	page{
		background-color:#EFF9F2 ;
	}
	.top{
		width: 750rpx;
		height: 260rpx;
		position: fixed;
		top: 0;
		z-index: 999;
		background: linear-gradient( 180deg, #98FFBB 0%, #EFF9F2 40%,#EFF9F2 20%,#EFF9F2 100%);
	}
	.order-nav-img{width: 32rpx;height: 32rpx;z-index: 999;}
	.order-nav{
		position: absolute;
		width: 100%;
		width:450rpx;
		margin-left: 32rpx;
		display: flex;
		align-items: center;
	}
	.nav-span{
		width: 176rpx;
		height: 40rpx;
	}
	.navtitle{
		font-size: 32rpx;
		color: black;
		font-weight: bold;
		margin-left:20rpx;
	}
	.navaddress{
		font-size: 28rpx;
		color: black;
		font-weight: bold;
		margin-left: 50rpx;
	}
	.navaddress::before{
		content: '';
		display: inline-block;
		width: 20rpx;
		height: 25rpx;
		background: url('https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/shoping/dw.png') center/cover;
		margin-left: -28rpx;
		margin-top: 0;
	}
	.nav-content{
		display: flex;
		align-items: center;
	}
	.search{
		width: 100%;
		height: 100%;
	}
	.search-sp{
		width: 100rpx;
		height: 28rpx;
		position: absolute;
		z-index: 10;
		line-height: 28rpx;
		border-left: #E8EDE9 1px solid;
		color: #36BE6A;
		font-size: 28rpx;
		top:19rpx;
		text-align: center;
	}
	.box{
		position: absolute;
		width: 708rpx;
		height: 72rpx;
		margin-left: 30rpx;
		display: flex;
	}
	.box1{
		width: 100rpx;
		height: 72rpx;
		position: absolute;
		z-index: 10;
		top: 0;
		right: 10rpx;
	}
	.bottom{
		width: 214rpx;
		height: 60rpx;
		position: absolute;
		bottom: 92rpx;
		right:100rpx;
	}
	.scrollx-box{
		width: 100%;
		position: absolute;
	}
	.main{
		width: 690rpx;
		margin-left: 30rpx;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
	}
	.mainbox{
		width: 336rpx;
		height: 484rpx;
		border-radius: 16rpx;
		background-color: white;
		position: relative;
		margin-top: 20rpx;
	}
	.mainimg{
		width: 100%;
		height: 338rpx;
		border-top-right-radius: 16rpx;
		border-top-left-radius: 16rpx;
	}
	.main-title{
		width: 320rpx;
		margin-left: 16rpx;
		font-size: 28rpx;
		color: #1F2921;
		height: 30rpx;
		margin-top: 16rpx;
		line-height: 26rpx;
		text-overflow:ellipsis;/*省略号 */
		 white-space:nowrap;/*溢出时不换行 */
		 overflow:hidden;/*溢出时隐藏 */
	}
	.main-price{
		min-width: 70rpx;
		height: 28rpx;
		color: #36BE6A;
		font-size: 36rpx;
		position: absolute;
		bottom: 50rpx;
		margin-left: 16rpx;
	}
	.main-btn{
		width: 128rpx;
		height: 48rpx;
		text-align: center;
		line-height: 48rpx;
		background-color: #1DCF79;
		border-radius: 42rpx;
		position: absolute;
		bottom: 32rpx;
		right: 16rpx;
		color: white;
		font-size: 24rpx;
	}
</style>